package com.stn.zjx.givingtreasure.utils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public class SoftInputUtils {



    /**
     * 隐藏软键盘
     *
     * @param acitivity
     */
    public static void closedSoftInput(Activity acitivity) {

             if (null != acitivity && acitivity.getCurrentFocus() != null) {
                 if (null != acitivity.getWindow()) {
                     acitivity.getWindow().getDecorView().clearFocus();
                     InputMethodManager im = ((InputMethodManager) acitivity
                             .getApplicationContext().getSystemService(
                                     Context.INPUT_METHOD_SERVICE));
                     if (null != im) {
                         im.hideSoftInputFromWindow(acitivity.getWindow()
                                         .getDecorView().getWindowToken(),
                                 InputMethodManager.HIDE_NOT_ALWAYS);
                     }
                 }
             }

    }
    /**
     * 打开软键盘
     *
     * @param acitivity
     */
    public static void openSoftInput(final Activity acitivity,View view) {
        InputMethodManager inputMethodManager =
                (InputMethodManager)acitivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.showSoftInput(view, InputMethodManager.HIDE_NOT_ALWAYS);
    }


    /**
     * 延时打开软键盘
     *
     * @param acitivity
     * @param delayMs
     */
    public static void openSoftInput(final Activity acitivity,View view, int delayMs) {
        if (null != acitivity) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    openSoftInput(acitivity,view);
                }
            }, delayMs);
        }
    }


}
